// pages/markingdetail/markingdetail.js
import http from '../../utils/newrequest'
Page({
    /**
     * 页面的初始数据
     */
    data: {
        reviewlist: [],
        count: '',
        values: '',
        zoomNum: 1,
        minScale: 0.1,
        maxScale: 3,
        lastDistance: 0,
        offsetX: 0,
        offsetY: 0,
        originX: 0,
        originY: 0,
        lastTouch: null,
        lastOffsetX: 0,
        lastOffsetY: 0,
        zoomNumVertical: 1,
        minScaleVertical: 0.1,
        maxScaleVertical: 3,
        lastDistanceVertical: 0,
        offsetXVertical: 0,
        offsetYVertical: 0,
        originXVertical: 0,
        originYVertical: 0,
        lastTouchVertical: null,
        lastOffsetXVertical: 0,
        lastOffsetYVertical: 0,
        questionVolume: false,
        questionVolumes: false,
        inputNumber: '',
        result: [],
        name_focus: false,
        correctIshow: false,
        successcorrectIshow: false,
        markpaperIshow: false,
        numValue: '',
        biaojiSuerIshow: false,
        systemInfo: {},
        succesBoxIshow: false,
        buttonDisabled: false,
        successIshow: false,
        hScreen: true,
        stepActive: -1,
        addStep: '',
        stepNumber: [],
        tranLeft: 0, // 向左偏移
        tranTop: 0,// 向右偏移
        imgBigshow: false,
        center_scrollTop: 0,
        setupIshow: false, //设置面板隐藏
        bcIshow: false,//背景颜色显示
        bcColor: '#eeeeee',//背景颜色
        buttondisabled1: 1,
        wtproblemname: undefined,
        switch1Checked: true,
        steparray: [],
        activeindex: 0,
        stepnumbers: 1,
        stepActiveishow: false,
        setupishowcontent: false,
        steplistBox: [],
        inputNumberBigIshow: false,
        reversenum: 1,
        landscapenum: 1,
        landscapenumishow: false,
        yjreconishow: false,
        souceCradid: '',
        score_group: [],
        scoregroupIshow: 0,
        nodefalutcardIshow: false,
        tasklist: [],
        scoreSorting: false,
        screenType: '',
        scrrenClass: '',
        scaleMin: 0.5,
        examId: '',
        assignmentConfigId: '',
        taskcardObject: {},
        questionInfo: {},
        errorQuestionlist: [],
        stepSizeNum: '',
        getTime: null,
        loading: false,
    },
    async submitProblem() {
        let { taskcardObject, wtproblemname, taskCardcontent } = this.data
        console.info(wtproblemname)
        if(wtproblemname==undefined||wtproblemname==''){
            wx.showToast({
              title: '请勾选问题类别',
            })
            return
        }
        let options = {
            url: '/task/questions',
            method: 'post',
            data: { id: taskcardObject.id, markerTeacherId: taskcardObject.teacherId, markerType: wtproblemname },
            header: { "content-type": "application/json;charset=UTF-8" }
        }
        let res = await http(options)
        if (res.data.code == 200) {
            this.setData({ questionVolumes: false,questionVolume:false,wtproblemname:'' })
            const index = taskCardcontent.findIndex(item => item.id == taskcardObject.id);
            if (index !== -1) {
                taskCardcontent.splice(index, 1);
                console.info(taskCardcontent)
                if (taskCardcontent.length > 0) {
                    wx.setStorageSync('tasklist', JSON.stringify(taskCardcontent));
                } else {
                    wx.removeStorageSync('tasklist')
                    this.getImage()
                }
            }
            this.setData({ taskcardObject: JSON.parse(wx.getStorageSync('tasklist'))[0] })
        }
    },
    //横屏打分弹出
    setuplandp() {
        this.setData({ landscapenumishow: true })
    },
    //打分步长排序
    reverseclick(e) {
        this.setData({ reversenum: e.currentTarget.dataset.id })
        this.cancelstpes()
    },
    landscapeclick(e) {
        this.setData({ landscapenum: e.currentTarget.dataset.id })
    },
    landscapeclicks() {
        let flag = this.data.landscapenum
        //console.log(flag, '1111111111');
        this.setData({ landscapenum: 1, landscapenumishow: false, setupIshow: false })
        wx.setPageOrientation({ orientation: 'landscape' })
        this.setData({ hScreen: false, stepNumber: [], inputNumber: '', inputNumberBigIshow: false })
    },
    reverseclick1(e) {
        this.setData({ reversenum: e.currentTarget.dataset.id, landscapenumishow: false })
        this.selectstepvale()
    },
    questionshow() {
        this.setData({
            questionVolume: true
        })
    },
    cancel() {
        this.setData({
            questionVolume: false
        })
    },
    cancels() {
        this.setData({
            questionVolumes: false
        })
    },
    radioChanges(e) {
        this.setData({ wtproblemname: e.detail.value, numValue: 2 })
    },
    landscapeclick1(e) {
        wx.setStorageSync('screenOrientation', e.currentTarget.dataset.id)
        this.setData({ landscapenum: e.currentTarget.dataset.id, landscapenumishow: false })
        if (e.currentTarget.dataset.id == 1) {
            wx.setPageOrientation({ orientation: 'landscape' })
            this.setData({ hScreen: false, stepNumber: [], inputNumber: '', inputNumberBigIshow: false })
        } else {
            wx.setPageOrientation({ orientation: 'portrait' })
            this.setData({ hScreen: true, stepNumber: [], inputNumber: '', inputNumberBigIshow: false })
        }
    },
    stepfunction(end, step, start) {
        let { reversenum, stepnumbers, hScreen } = this.data
        if (typeof step === 'string' && step.includes(',')) {
            let steps = step.split(',').map(s => parseFloat(s.trim())).filter(s => !isNaN(s));
            if (reversenum == 2) {
                steps.reverse();
            }

            this.setData({
                steplistBox: steps,
                score_group: [{
                    values: steps
                }]
            });
            // //console.log(steps, '自定义step列表');
            return;
        } else if (Array.isArray(step)) {
            let steps = step;
            if (reversenum == 2) {
                steps.reverse();
            }
            this.setData({
                steplistBox: steps,
                score_group: [{
                    values: steps
                }]
            });
            // //console.log(steps, '数组step列表');
            return;
        }
        if (!start) {
            start = 0
        }
        let newliststep = []
        let i = start;
        for (; i < end; i += step) {
            newliststep.push(i)
        } if (i >= end) {
            newliststep.push(end)
        }
        // this.setData({steplistBox:newliststep})
        if (reversenum == 2) {
            this.setData({ steplistBox: newliststep.reverse() })
        } else {
            this.setData({ steplistBox: newliststep })
        }
        //console.info(newliststep)
        var scoreSegments = [];
        var segmentSize = 10; // 每个分数段的大小，向上取整
        // 创建分数段
        for (let i = 0; i < newliststep.length; i += segmentSize) {
            var segmentEnd = Math.min(i + segmentSize, newliststep.length);
            scoreSegments.push({
                // name: '分数段 ' + (scoreSegments.length + 1),
                values: newliststep.slice(i, segmentEnd)
            });
        }
        //console.info(scoreSegments, '333333333333333333333333')
        this.setData({ score_group: scoreSegments })
        // }
    },
    // 切换分数组
    scoreGroupTap(e) {
        // //console.info(e)
        this.setData({ scoregroupIshow: e.currentTarget.dataset.index })
    },
    //选择打分步长
    selectstepvale() {
        let { stepnumbers, scoreall } = this.data
        this.stepfunction(scoreall, stepnumbers)
    },
    //设置弹出按钮
    setupbutton() {
        this.setData({ setupishowcontent: true, setupIshow: false, inputNumberBigIshow: false })
    },
    //设置页面返回
    backDeltastep() {
        let { landscapenum } = this.data
        this.setData({ setupishowcontent: false, inputNumber: '', inputNumberBigIshow: false, scoreSorting: false, stepActiveishow: false })
        this.selectstepvale()
        wx.setPageOrientation({ orientation: 'portrait' })
        this.setData({ hScreen: true, stepNumber: [], inputNumber: '', inputNumberBigIshow: false })
    },
    //打分步长点击弹窗
    scorestepclick() {
        this.setData({ stepActiveishow: true })
    },
    // 分数排序
    scorestepclicks() {
        //console.log(111);
        this.setData({ scoreSorting: true })
    },
    //打分步长点击显示
    stpelistclick(e) {
        let index = e.currentTarget.dataset.index
        let stpenum = e.currentTarget.dataset.number
        wx.setStorageSync('stepnum', stpenum)
        this.setData({ activeindex: index, stepnumbers: stpenum, stepActiveishow: false, landscapenumishow: false })
        let { scoreall } = this.data
        this.stepfunction(scoreall, stpenum)
    },
    stpelistclick1(e) {
        let index = e.currentTarget.dataset.index
        let stpenum = e.currentTarget.dataset.number
        wx.setStorageSync('stepnum', stpenum)
        this.setData({ activeindex: index, landscapenumishow: false, stepnumbers: stpenum })
        let { scoreall } = this.data
        this.stepfunction(scoreall, stpenum)
    },
    //取消步长
    cancelstpe() {
        this.setData({ stepActiveishow: false })
    },
    cancelstpes() {
        this.setData({ scoreSorting: false })
    },
    //switch开关自动提交
    switch1Change(e) {
        this.setData({ switch1Checked: e.detail.value, landscapenumishow: false })
    },
    //问题卷设置
    wtjClick(e) {
        let name = e.currentTarget.dataset.name
        //console.info(name)
        this.setData({ wtproblemname: name, numValue: 2 })
    },
    //设置
    setUp() {
        this.setData({ setupIshow: true })
    },
    //背景颜色显示
    backgroundColor() {
        this.setData({ bcIshow: true })
    },
    //切换背景颜色
    bcTap(e) {
        let bc = e.currentTarget.dataset.color
        this.setData({ bcColor: bc, bcIshow: false, setupIshow: false, landscapenumishow: false })
        wx.showToast({
            title: '修改成功',
            icon: "none"
        })
    },
    closeSet() {
        this.setData({ setupIshow: false })
    },
    // 退回上一步
    async backDelta() {
        let { souceCradid } = this.data
        if (souceCradid) {
            let id = JSON.parse(wx.getStorageSync('newtoken')).id
            let options = {
                url: '/updateTasktype2BySourceId',
                method: 'POST',
                data: { sourceId: souceCradid },
                header: { "content-type": "application/json;charset=UTF-8" }
            }
            let res = await http(options)
        }
        // 清除 tasklist 缓存
        wx.removeStorageSync('tasklist')
        wx.redirectTo({
            url: '/pages/newmarkinglist/newmarkinglist',
        })
    },
    //点击修正
    correctMark() {
        this.setData({ correctIshow: true })
    },
    //隐藏设置
    ycopcity() {
        this.setData({ setupIshow: false, landscapenumishow: false, biaojiSuerIshow: false, yjreconishow: false })
    },
    inputChangestep(e) {
        let { switch1Checked } = this.data
        if (switch1Checked) {
            this.setData({ inputNumberBigIshow: true, inputNumber: e.currentTarget.dataset.val })
            this.submitScore()
        } else {
            this.setData({ inputNumberBigIshow: true, inputNumber: e.currentTarget.dataset.val })
        }
    },
    //进入回评详情
    goReview(e) {
        this.setData({ yjreconishow: false })
        let con = e.currentTarget.dataset.con
        let { stepnumbers } = this.data
        wx.navigateTo({
            url: '/pages/review/review?con=' + JSON.stringify(con) + '&stepbc' + stepnumbers
        })
    },
    //input 输入框
    inputChange(e) {
        this.setData({ inputNumberBigIshow: true })
        if (e.currentTarget.dataset.leixing == 'ks') {
            this.setData({ inputNumber: '', result: [] })
        }
        let val = e.currentTarget.dataset.val
        let { result } = this.data
        if (result.length === 0 && val === ".5") {
            return false;
        }
        result.push(val);
        let num = result.join("");
        this.setData({ name_focus: true, inputNumber: num })
        if (this.data.inputNumber.indexOf('.5') != -1) {
            if (val === ".5") {
                this.setData({ buttonDisabled: true })
            } else {
                this.setData({ buttonDisabled: false })
                this.setData({ result: [], inputNumber: '', inputNumberBigIshow: false })
                result.push(val);
                let num = result.join("");
                this.setData({ name_focus: true, inputNumber: num })
            }
        }
        if (result[0] == 0) {
            this.setData({ buttonDisabled: false })
            if (val != ".5") {
                this.setData({ result: [], inputNumber: '', inputNumberBigIshow: false })
                result.push(val);
                let num = result.join("");
                this.setData({ name_focus: true, inputNumber: 0, buttonDisabled: false })
            }
        }
    },
    //删除input
    cancelDel() {
        let { result } = this.data
        result.pop();
        let num = result.join("");
        this.setData({ inputNumber: num, buttonDisabled: false })
    },
    // 零分，满分
    correctMf(e) {
        let val = e.currentTarget.dataset.score
        this.setData({ name_focus: true, inputNumber: val })
    },
    async updateReviewProgress() {
        // //console.log("更新批阅进度");
        try {
            const { examId, assignmentConfigId } = this.data;
            const res = await http({
                url: `/task/teacher/stats/reviewProgress?examId=${examId}&assignmentConfig=${assignmentConfigId}`,
                method: 'get'
            });

            if (res.data.code === 200 && res.data.data) {
                this.setData({
                    'questionInfo.completedTasks': res.data.data.completedTasks,
                    'questionInfo.planTasks': res.data.data.planTasks
                });
            } else {
                console.warn('批阅进度接口失败：', res.data);
            }
        } catch (e) {
            console.error('批阅进度接口调用异常：', e);
        }
    },
    //分数提交成功
    submitScore: async function () {
        if (this.data.loading || (this.data.taskCardcontent.length == 1 && this.data.getTime && new Date().getTime() - this.data.getTime < 500)) {

            wx.showToast({
                title: '您点击的太频繁了',
                icon: 'none',
                duration: 1000 //持续的时间
            })
            return;
        }
        let that = this
        this.setData({ buttondisabled1: 2, inputNumberBigIshow: false })
        if (wx.getStorageSync('newtoken')) {
            let { inputNumber, scoreall, taskcardObject, taskCardcontent } = that.data
            let { souceCradid, content } = this.data
            let par = '1' + inputNumber
            if (par.length >= 2) {
                if (inputNumber <= scoreall) {
                    let str = inputNumber.toString();
                    let reg = /^[0-9]+(.[0-9]{1})?$/
                    if (str.indexOf(".") > -1) {
                        //console.info('11111')
                        if (!reg.test(str)) {
                            let reg1 = /^\d+\.5$/
                            if (!reg1.test(str)) {
                                this.setData({ buttondisabled1: 1, buttonDisabled: false })
                                wx.showToast({
                                    title: '您输入的分值不符合规范',
                                    icon: 'error',
                                    duration: 2000 //持续的时间
                                })
                                return false
                            }
                        }
                    }
                    let options = {
                        url: '/task/teacher/assignment',
                        method: 'put',
                        data: { id: taskcardObject.id, teacherId: taskcardObject.teacherId, score: inputNumber },
                        header: { "content-type": "application/json;charset=UTF-8" }
                    }
                    this.data.loading = true;
                    let res = await http(options)
                    if (res.data.code == 200) {
                        this.setData({ successcorrectIshow: false, correctIshow: false, inputNumber: '', successIshow: false, result: [], buttondisabled1: 1, buttonDisabled: false, })
                        const index = taskCardcontent.findIndex(item => item.id == taskcardObject.id);
                        if (index !== -1) {
                            taskCardcontent.splice(index, 1);
                            if (taskCardcontent.length > 0) {
                                wx.setStorageSync('tasklist', JSON.stringify(taskCardcontent));
                                this.data.loading = false;
                            } else {
                                wx.removeStorageSync('tasklist')
                                this.getImage()
                            }
                        }else{
                            this.data.loading = false;
                        }
                        await this.updateReviewProgress();
                        this.setData({ taskcardObject: JSON.parse(wx.getStorageSync('tasklist'))[0] })
                    } else {
                        this.data.loading = false;
                    }
                } else {
                    this.setData({ buttondisabled1: 1, buttonDisabled: false })
                    wx.showToast({
                        title: '得分超出满分限制',
                        icon: 'error',
                        duration: 2000 //持续的时间 
                    })
                }
            } else {
                this.setData({ buttondisabled1: 1, buttonDisabled: false })
                wx.showToast({
                    title: '得分未设置',
                    icon: 'error',
                    duration: 2000 //持续的时间
                })
            }
        } else {
            wx.redirectTo({
                url: '/pages/newbootpage/newbootpage',
            })
        }
    },
    //修改分数成功
    correctClose() {
        this.setData({ successcorrectIshow: false })
    },
    // 标记
    markpaper() {
        // this.setData({biaojiSuerIshow:true,setupIshow:false})
        this.setData({
            questionVolumes: true
        })
    },
    //确认标记
    suremark() {
        this.setData({ markpaperIshow: false, biaojiSuerIshow: false })
        this.submitScore()
    },
    //取消标记
    cancelmark() {
        this.setData({ markpaperIshow: false })
    },
    //答案解析
    answer(e) {
        this.setData({ setupIshow: false })
        let ans = e.currentTarget.dataset.answer
        wx.navigateTo({
            url: '/pages/answeranalysis/answeranalysis?answer=' + ans,
        })
    },
    //请选择标记类型
    radioChange(e) {
        let num = e.detail.value
        this.setData({ numValue: num })
    },
    //确定标记
    suremarkBj() {
        this.setData({ biaojiSuerIshow: false })
        let { numValue } = this.data
        if (numValue == '2') {
            this.setData({ markpaperIshow: true })
        } else {
            this.setData({ biaojiSuerIshow: false, markpaperIshow: false })
        }
    },
    //关闭标记
    closeLeixing() {
        this.setData({ biaojiSuerIshow: false })
    },
    // 用步长和满分计算步长的倍数
    stepfullScore(maxScore, step) {
        let arrsy = []
        for (let i = step; i <= maxScore; i += step) {
            arrsy.push(i)
        }
        this.setData({ steparray: arrsy })
    },
    // 获取图片
    async getImage(params) {
        let that = this
        let { examId, assignmentConfigId, stepnumbers } = this.data
        let options = {
            url: '/task/teacher/assignment/reviewList',
            method: 'get',
            data: {
                examId: examId,
                assignmentConfigId: assignmentConfigId,
            },
            header: { "content-type": "application/json;charset=UTF-8" }
        }
        let res = await http(options)
        //console.info(res, 'resssss')
        if (res.data.code == 200) {
            if (res.data.rows.length > 0) {
                wx.setStorageSync('tasklist', JSON.stringify(res.data.rows))
                let stepSizeStr = res.data.rows[0].stepSize
                // //console.log(stepSizeStr, '步长字符串');

                if (stepSizeStr.includes(',')) {
                    stepSizeStr = stepSizeStr.split(',').map(s => Number(s.trim()));
                } else {
                    stepSizeStr = Number(stepSizeStr);
                }
                this.setData({
                    stepSizeNum: stepSizeStr
                });
                if (wx.getStorageSync('stepnum')) {
                    this.stepfunction(res.data.rows[0].fullScore, Number(wx.getStorageSync('stepnum')))
                    this.stepfullScore(res.data.rows[0].fullScore, stepSizeStr)
                } else {
                    this.stepfunction(res.data.rows[0].fullScore, stepSizeStr)
                    this.stepfullScore(res.data.rows[0].fullScore, stepSizeStr)
                }
                this.setData({ successIshow: false, taskcardObject: res.data.rows[0], taskCardcontent: res.data.rows, scoreall: res.data.rows[0].fullScore })
            } else {
                //console.log(this.data.questionInfo.completedTasks, this.data.questionInfo.planTasks, '已阅读数/计划数');

                if (this.data.questionInfo.completedTasks == this.data.questionInfo.planTasks) {
                    this.setData({
                        successIshow: true,
                        nodefalutcardIshow: false
                    });
                } else {
                    this.setData({
                        successIshow: false,
                        nodefalutcardIshow: true
                    });
                }
            }
        } else {
            wx.showToast({
                title: res.data.msg,
                icon: 'error',
                duration: 2000 //持续的时间
            })
        }
        this.data.getTime = new Date().getTime();
        this.data.loading = false;
    },
    scrollToTop() {
        this.setAction({
            scrollTop: 0
        })
    },
    //跳到阅卷列表
    closeLinkMarklist() {
        wx.redirectTo({
            url: '/pages/newmarkinglist/newmarkinglist',
        })
    },
    nodefalutcardClose() {
        // wx.reload(); // 刷新当前页面
        wx.redirectTo({
            url: '/pages/newmarkinglist/newmarkinglist',
        })
    },
    //回评
    huipingreview() {
        const { taskcardObject } = this.data;
        const pageNum = 1;
        const pageSize = 10;
        const teacherId = taskcardObject.teacherId;
        const examId = taskcardObject.examId;
        const assignmentConfigId = taskcardObject.assignmentConfigId;

        const query = `pageNum=${pageNum}&pageSize=${pageSize}&teacherId=${teacherId}&examId=${examId}&assignmentConfigId=${assignmentConfigId}`;
        wx.redirectTo({
            url: `/pages/newreviewlist/newreviewlist?${query}`,
        });
        this.setData({ setupIshow: false })
    },
    // 阅卷记录
    huipingreview1() {
        this.setData({ yjreconishow: true })
    },
    //步长
    step(e) {
        let num = e.currentTarget.dataset.active
        this.setData({ stepActive: num })
    },
    stepAddtjnum(e) {
        let { num, stepNumber, stepActive, inputNumber } = this.data
        let tranLeft = (e.detail.x) + 'px'
        let tranTop = (e.detail.y) + 'px'
        let arraylist = []
        let numul = 0
        var lists = this.data.stepNumber;
        var newData = {};
        if (stepActive == 0) {
            newData = { scorenum: 0.5, tranLeft: tranLeft, tranTop: tranTop }
            lists.push(newData);//实质是添加lists数组内容，使for循环多一次
            numul = 0.5
        } else if (stepActive == 1) {
            newData = { scorenum: 1, tranLeft: tranLeft, tranTop: tranTop }
            lists.push(newData);//实质是添加lists数组内容，使for循环多一次
            numul = 1
        } else if (stepActive == 2) {
            newData = { scorenum: 2, tranLeft: tranLeft, tranTop: tranTop }
            lists.push(newData);//实质是添加lists数组内容，使for循环多一次
            numul = 2
        } else {
            wx.showToast({
                title: '您未选择步长',
                icon: 'success',
                duration: 2000 //持续的时间
            })
        }
        let totalnum = parseFloat(inputNumber + numul)
        this.setData({ stepNumber: lists, inputNumber: totalnum })
    },
    //设为问题卷
    async errorQuestion() {
        let options = {
            url: '/system/dict/data/type/exception_exam_questions',
            method: 'get',
            header: { "content-type": "application/json;charset=UTF-8" }
        }
        let res = await http(options)
        if (res.data.code == 200) {
            this.setData({ errorQuestionlist: res.data.data })
        }
    },
    onLoad: function (options) {
        this.errorQuestion()
        // taskCardconten
        this.setData({ examId: options.examId, assignmentConfigId: options.assignmentConfigId, questionInfo: JSON.parse(wx.getStorageSync('questionInfo')) })
        wx.setPageOrientation({ orientation: 'landscape' })
        // this.getImage()
        if (wx.getStorageSync('tasklist')) {
            this.setData({ taskCardcontent: JSON.parse(wx.getStorageSync('tasklist')), taskcardObject: JSON.parse(wx.getStorageSync('tasklist'))[0], scoreall: JSON.parse(wx.getStorageSync('tasklist'))[0].fullScore })
            this.stepfunction(JSON.parse(wx.getStorageSync('tasklist'))[0].fullScore, Number(JSON.parse(wx.getStorageSync('tasklist'))[0].stepSize))
            this.stepfullScore(JSON.parse(wx.getStorageSync('tasklist'))[0].fullScore, Number(JSON.parse(wx.getStorageSync('tasklist'))[0].stepSize))
        } else {
            this.setData({ examId: JSON.parse(wx.getStorageSync('questionInfo')).examId, assignmentConfigId: JSON.parse(wx.getStorageSync('questionInfo')).assignmentConfigId })
            this.getImage()
        }
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        let screenOrientation = null
        if (wx.getStorageSync('screenOrientation')) {
            screenOrientation = wx.getStorageSync('screenOrientation')
            if (screenOrientation == 1) {
                // 横屏
                wx.setPageOrientation({ orientation: 'landscape' })
                this.setData({ hScreen: false })
            } else if (screenOrientation == 2) {
                wx.setPageOrientation({ orientation: 'portrait' })
                this.setData({ hScreen: true })
            }
        } else {
            wx.setPageOrientation({ orientation: 'landscape' })
            this.setData({ hScreen: false })
        }
        var that = this
        wx.getSystemInfo({
            success: (result) => {
                that.setData({ systemInfo: result })
                if (result.platform === 'ios') {
                    const systemInfo = wx.getWindowInfo()
                    // 屏幕宽度和高度
                    const screenWidth = systemInfo.windowWidth;
                    const screenHeight = systemInfo.windowHeight;
                    // 根据屏幕大小决定使用哪种样式
                    if (screenWidth < 768) {
                        // 屏幕宽度小于375px，适用于小屏幕设备
                        this.setData({ screenType: 'small', scrrenClass: 'mainbox2' })

                    } else {
                        // 屏幕宽度大于等于375px，适用于大屏幕设备
                        this.setData({ screenType: 'large', scrrenClass: 'mainbox2ipad' })
                    }
                } else {
                    const systemInfo = wx.getWindowInfo()
                    // 屏幕宽度和高度
                    const screenWidth = systemInfo.windowWidth;
                    const screenHeight = systemInfo.windowHeight;
                    // 根据屏幕大小决定使用哪种样式
                    if (screenWidth < 768) {
                        // 屏幕宽度小于375px，适用于小屏幕设备
                        this.setData({ screenType: 'small', scrrenClass: '' })
                    } else {
                        // 屏幕宽度大于等于375px，适用于大屏幕设备
                        this.setData({ screenType: 'large', scrrenClass: '' })
                    }
                }
            }
        })
    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {
        this.setData({ hScreen: false, landscapenum: 1, stepNumber: [], inputNumber: '', inputNumberBigIshow: false })
    },
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {
        wx.removeStorageSync('stepnum')
    },
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {
        return {
            title: 'scroll-view',
            path: 'page/component/pages/scroll-view/scroll-view'
        }
    },
    // 切换横屏
    HorizontalScreen() {
        wx.setPageOrientation({ orientation: 'landscape' })
        this.setData({ hScreen: false, stepNumber: [], inputNumber: '', inputNumberBigIshow: false })
    },
    // 切换竖屏
    verticalScreen() {
        wx.setPageOrientation({ orientation: 'portrait' })
        this.setData({ hScreen: true, stepNumber: [], inputNumber: '', inputNumberBigIshow: false })
    },
    onTouchStart(e) {
        if (e.touches.length === 2) {
            const distance = this.getDistance(e.touches[0], e.touches[1]);
            const midpoint = this.getMidpoint(e.touches[0], e.touches[1]);
            this.setData({
                lastDistance: distance,
                originX: midpoint.x,
                originY: midpoint.y,
            });
        } else if (e.touches.length === 1) {
            this.setData({
                lastTouch: e.touches[0],
                lastOffsetX: this.data.offsetX,
                lastOffsetY: this.data.offsetY
            });
        }
    },
    onTouchMove(e) {
        if (e.touches.length === 2) {
            const newDistance = this.getDistance(e.touches[0], e.touches[1]);
            let scaleChange = newDistance / this.data.lastDistance;
            let newZoom = this.data.zoomNum * scaleChange;
            newZoom = Math.max(this.data.minScale, Math.min(newZoom, this.data.maxScale));

            const midpoint = this.getMidpoint(e.touches[0], e.touches[1]);

            this.setData({
                zoomNum: newZoom,
                lastDistance: newDistance,
                originX: midpoint.x,
                originY: midpoint.y
            });
        } else if (e.touches.length === 1) {
            const touch = e.touches[0];
            const dx = touch.pageX - this.data.lastTouch.pageX;
            const dy = touch.pageY - this.data.lastTouch.pageY;

            this.setData({
                offsetX: this.data.lastOffsetX + dx,
                offsetY: this.data.lastOffsetY + dy
            });
        }
    },
    onTouchEnd() {
        this.setData({
            lastTouch: null
        });
    },
    getDistance(p1, p2) {
        const x = p1.pageX - p2.pageX;
        const y = p1.pageY - p2.pageY;
        return Math.sqrt(x * x + y * y);
    },
    getMidpoint(p1, p2) {
        return {
            x: (p1.pageX + p2.pageX) / 2,
            y: (p1.pageY + p2.pageY) / 2
        };
    },
    onTouchStartVertical(e) {
        if (e.touches.length === 2) {
            const distance = this.getDistanceVertical(e.touches[0], e.touches[1]);
            const midpoint = this.getMidpointVertical(e.touches[0], e.touches[1]);
            this.setData({
                lastDistanceVertical: distance,
                originXVertical: midpoint.x,
                originYVertical: midpoint.y,
            });
        } else if (e.touches.length === 1) {
            this.setData({
                lastTouchVertical: e.touches[0],
                lastOffsetXVertical: this.data.offsetXVertical,
                lastOffsetYVertical: this.data.offsetYVertical
            });
        }
    },
    onTouchMoveVertical(e) {
        if (e.touches.length === 2) {
            const newDistance = this.getDistanceVertical(e.touches[0], e.touches[1]);
            let scaleChange = newDistance / this.data.lastDistanceVertical;
            let newZoom = this.data.zoomNumVertical * scaleChange;
            newZoom = Math.max(this.data.minScaleVertical, Math.min(newZoom, this.data.maxScaleVertical));
            const midpoint = this.getMidpointVertical(e.touches[0], e.touches[1]);
            this.setData({
                zoomNumVertical: newZoom,
                lastDistanceVertical: newDistance,
                originXVertical: midpoint.x,
                originYVertical: midpoint.y
            });
        } else if (e.touches.length === 1) {
            const touch = e.touches[0];
            const dx = touch.pageX - this.data.lastTouchVertical.pageX;
            const dy = touch.pageY - this.data.lastTouchVertical.pageY;

            this.setData({
                offsetXVertical: this.data.lastOffsetXVertical + dx,
                offsetYVertical: this.data.lastOffsetYVertical + dy
            });
        }
    },
    onTouchEndVertical() {
        this.setData({
            lastTouchVertical: null
        });
    },
    getDistanceVertical(p1, p2) {
        const x = p1.pageX - p2.pageX;
        const y = p1.pageY - p2.pageY;
        return Math.sqrt(x * x + y * y);
    },
    getMidpointVertical(p1, p2) {
        return {
            x: (p1.pageX + p2.pageX) / 2,
            y: (p1.pageY + p2.pageY) / 2
        };
    }
})